export default {
  components: {},
  data() {
    return {
      winTitle: '新增',
      isShowAddDialog: false,
      curRecordId: null,
      winWidth: 500,
      btns: [
        {id: 'flush', label: '刷新', icon: 'el-icon-refresh', type: 'iconBtn'},
        {id: 'add', label: '新增', icon: 'el-icon-plus', isPrimary: true},
        {id: 'mod', label: '修改', icon: 'el-icon-edit'},
        {id: 'del', label: '删除', icon: 'el-icon-delete'}
      ]
    };
  },
  computed: {

  },
  methods: {
    //刷新数据
    flush(){
      this.searchGridByCondition&&this.searchGridByCondition();
      this.$emit('flush', '');
    },
    //按钮点击事件
    btnClick({id}){
      this[id]&&this[id]();
    },
    //删除操作
    del(id){
      let rowId=this.$refs.tableObj.getRowIds();
      if(id){
        rowId = id;
      }
      if(rowId!=null&&rowId!==''){
        let str = '该记录';
        if(this.delNameKey&&rowId[this.delNameKey]){
          str = `<span class="delTipsNameStyle">${rowId[this.delNameKey]}</span>`;
        }
        this.$confirm(`此操作将永久删除${str}, 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          dangerouslyUseHTMLString: true,
          type: 'warning'
        }).then(() => {
          this.delOk&&this.delOk(rowId);
        }).catch(err => {
          this.$alert(err.msg||err, {
            confirmButtonText: '确定',
            title: '提示',
            type: 'error'
          });
        });

      }else{
        this.$message.error('请选择相应的记录后再进行操作！');
      }
    },
    //购买按钮
    purchase() {
      this.winTitle='购买';
      this.isShowPurchaseWin = true;
      this.beforeAdd&&this.beforeAdd();
    },
    // 购买记录按钮
    purchaseRecords() {
      this.isShowPurchaseRecordsWin = true;
    },
    //关闭新增窗口
    closeAddWin(){
      this.isShowAddDialog=false;
      this.isShowPurchaseWin = false;
    },
    //添加按钮
    add(){
      this.winTitle='新增';
      this.beforeAdd&&this.beforeAdd();
      this.isShowAddDialog=true;
      this.winTitle='新增';
    },
    //修改操作
    mod(id){
      let rowId=this.$refs.tableObj.getRowId();
      if(id){
        rowId = id;
      }
      if(rowId!=null&&rowId!==''){
        this.isShowAddDialog=true;
        this.winTitle='修改';
        this.beforeMod&&this.beforeMod();
        this.loadRecord&&this.loadRecord(rowId);
      }else{
        this.$message.error('请选择相应的记录后再进行操作！');
      }
    },
    //添加确定
    addConfirm(){
      //校验数据
      if(this.$refs.dynamicForm.validate()){
        this.confirmOk&&this.confirmOk();
      }
    }
  }

};